﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web.Mvc;

namespace Cormant.Mvc.Web
{
    public class MvcGridViewColumn
    {
        #region MvcGridViewColumn : Properties.
        public string HeaderCssClass { get; set; }
        public string HeaderText { get; set; }
        public string ItemCssClass { get; set; }
        #endregion

        #region MvcGridViewColumn : Method.
        public virtual MvcTableCell CreateTableCell(MvcTable table, HtmlHelper html, object dataItem)
        {
            MvcTableRow row = table.Rows.LastOrDefault();
            if (row != null)
            {
                MvcTableCell cell = new MvcTableCell(html);
                cell.CssClass = this.ItemCssClass;
                row.Cells.Add(cell);
                return cell;
            }
            else
                throw new ArgumentException("table has no rows.", "table");
        }

        public virtual MvcTableCellHeader CreateTableCellHeader(MvcTable table, HtmlHelper html)
        {
            MvcTableRow row = table.Rows.LastOrDefault();
            if (row != null)
            {
                MvcTableCellHeader cellHeader = new MvcTableCellHeader(html);
                cellHeader.CssClass = this.HeaderCssClass;
                cellHeader.Text = this.HeaderText;
                row.Cells.Add(cellHeader);
                return cellHeader;
            }
            else
                throw new ArgumentException("table has no rows.", "table");
        }
        #endregion
    }
}
